<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
  <title>JSON-RPC DOJO example</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js"
       djConfig="parseOnLoad: true, dojoBlankHtmlUrl: 'blank.html'"></script>
<style type="text/css">
<!--
    @import "http://ajax.googleapis.com/ajax/libs/dojo/1.3/dijit/themes/tundra/tundra.css";
-->
</style>

  <script type="text/javascript">
  //  djConfig.usePlainJson = true;
  dojo.require('dojo.rpc.JsonService');
  dojo.require('dijit.form.Button');
  dojo.require('dijit.form.TextBox');
  dojo.require('dojo.io.iframe');
  var proxy;
  function setup() {
    var smdURL = '/hgm/server/api.php';
    proxy = new dojo.rpc.JsonService({serviceUrl: smdURL ,
    methods: [
        {
            name: 'addurl',
            parameters: [{name: 'url'}],
            handleAs: 'json'
        }
    ],
    timeout: 100000}
    );
  }

function XMLtoString(elem){

var serialized;

try {
// XMLSerializer exists in current Mozilla browsers
serializer = new XMLSerializer();
serialized = serializer.serializeToString(elem);
}
catch (e) {
// Internet Explorer has a different approach to serializing XML
serialized = elem.xml;
}

return serialized;
}

  function scan_url_result(result) {
      addurlBack("Done scanning");
      dojo.byId('scan_results').innerHTML = result;
      console.debug(result);
  }

  function scan_url() {
     if (!(url = dojo.byId('url_field').value))
     {
         if (!(url = url_value)) return;
     }
     console.debug("scanning " + url);
     
     proxy.addurl(url).addCallback(scan_url_result);
  }

  dojo.addOnLoad(setup);

  function update_watch()
  {
      console.debug(dojo.byId('url_frame').src);
  }

var url_value;

  function view_url()
  {
      source = dojo.byId('url_field');
      console.debug('changing source to ' + source.value);

      if (!source.value) 
      {
          return;
      }

      dojo.byId('url_frame').src = source.value;
      dojo.style('url_frame', 'display', 'block');
      dojo.byId('url_echo').innerHTML = url_value = source.value;
      source.value = '';
      dojo.style(dijit.byId('scan_button').domNode, 'display', 'block');
  }


  function apply_url(source)
  {
      if (source.id == 'url_field')
          {
              view_url();
          }
      else if (source.id == 'url_frame')
          {
              dojo.byId('url_field').value = source.src;
          }
      else
          {
              console.debug('apply_url(' + source.id + ') passthrough');
          }
  }
</script>
  <style>
      .view_button,
      .scan_button
      {
          font-family: Arial, Helvetica, sans-serif;
          font-weight: bold;
          width: 50px;
          float: left;
          height: 20px;
      }

      #url_echo
      {
          font-family: Verdana, Arial, Helvetica, sans-serif;
          color: #999;
          text-align: left;
          padding: 3px;
          font-weight: bold;
          width: 300px;
          font-size: 80%;
          float: left
      }

      #url_field
      {
          float: left;
          width: 400px
      }
  </style>
</head>

<body>
    <fieldset id="window_fieldset">
        <label>Open windows</label>
       	<h2>Choose A Url</h2>
       	<div id="submission">
        <input type="text" id="url_field" name="url_field"
               dojoType="dijit.form.TextBox" 
               onChange="apply_url(this)"
               onDrop="apply_url(this)"
               onBlur="apply_url(this)"/>
        <button id="view_button"
                class="view_button"
                onClick="view_url()"
                dojoType="dijit.form.Button">View</button><br clear="all" />
        <iframe id="url_frame"
                width="400px"
                height="300px"
                border="1px"
                style="font-size: 50%; display: none"
                src="new_frame_start.html">
        Drag a URL from your browser or bookmarks to this window
        </iframe><br clear="all" />
            <div id="url_echo">
            </div>
        <button id="scan_button" style="width: 50px; float: left"
                class="scan_button"
                onClick="scan_url"
                dojoType="dijit.form.Button">Scan</button> 
        <br clear="all" /></span>
        <div><h3>Results</h3></div>
        <div id="scan_results">
        </div>
    </fieldset>
</body>
</html>